package com.mnf.server;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.nio.SelectChannelConnector;

public class HelloWorld extends AbstractHandler {
	public void handle(String target, Request baseRequest,
			HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		System.err.println(request.getRequestURL().toString());
		
		response.setContentType("text/html;charset=utf-8");
		response.setStatus(HttpServletResponse.SC_OK);
		baseRequest.setHandled(true);
		response.getWriter().println("<h1>Hello World</h1>");
	}

	public static void main(String[] args) throws Exception
	{
		Server server = new Server();
		SelectChannelConnector connector1 = new SelectChannelConnector();
		connector1.setHost("127.0.0.1");
		connector1.setPort(80);
		connector1.setName("admin");
		
		server.setConnectors(new Connector[] {connector1});
	 
		server.setHandler(new HelloWorld());

		server.start();
		server.join();
	}
}
